restage: New git-annex command, handles restaging unlocked files
authorJoey Hess <joeyh@joeyh.name>
Fri, 23 Sep 2022 20:29:28 +0000 (16:29 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 23 Sep 2022 20:29:59 +0000 (16:29 -0400)
This is much easier and less failure-prone than having the user run
git update-index --refresh themselves.

Sponsored-by: Dartmouth College's DANDI project
Annex/Link.hs
CHANGELOG
CmdLine/GitAnnex.hs
Command/Restage.hs [new file with mode: 0644]
Command/VCycle.hs
doc/bugs/reports_file___34__modified__34___whenever_it_is_not.mdwn
doc/bugs/reports_file___34__modified__34___whenever_it_is_not/comment_16_4b8a360c38dfa4c8d22e3a96fbace0e5._comment [new file with mode: 0644]
doc/git-annex-restage.mdwn [new file with mode: 0644]
doc/git-annex.mdwn
git-annex.cabal

index 496a071535c9d5fb104970345457dc807383a808..5329febcdb51940623896418dabb7fbdaba8a2c5 100644 (file)
@@ -316,7 +316,7 @@ unableToRestage mf = unwords
        , "This is only a cosmetic problem affecting git status; git add,"
        , "git commit, etc won't be affected."
        , "To fix the git status display, you can run:"
-       , "git update-index -q --refresh " ++ fromMaybe "<file>" mf
+       , "git-annex restage"
        ]
 
 {- Parses a symlink target or a pointer file to a Key.
index 172f0c14ec599c4259678a5ed4c05bc4fdb91df6..1a9b38adb11bc82e9fae1b7646e37a59bd2c3c93 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -31,6 +31,7 @@ git-annex (10.20220823) UNRELEASED; urgency=medium
   * Improved handling of --time-limit when combined with -J
   * Fix updating git index file after getting an unlocked file 
     when annex.stalldetection is set.
+  * restage: New git-annex command, handles restaging unlocked files.
   * test: Added --test-with-git-config option.
 
  -- Joey Hess <id@joeyh.name>  Mon, 29 Aug 2022 15:03:04 -0400
index 08c2bd832b8eec3692886480b2816bc7409884d3..b845047cde95b2314f105f27d95195c2239c8dcc 100644 (file)
@@ -1,6 +1,6 @@
 {- git-annex main program
  -
- - Copyright 2010-2021 Joey Hess <id@joeyh.name>
+ - Copyright 2010-2022 Joey Hess <id@joeyh.name>
  -
  - Licensed under the GNU AGPL version 3 or higher.
  -}
@@ -114,6 +114,7 @@ import qualified Command.Proxy
 import qualified Command.DiffDriver
 import qualified Command.Smudge
 import qualified Command.FilterProcess
+import qualified Command.Restage
 import qualified Command.Undo
 import qualified Command.Version
 import qualified Command.RemoteDaemon
@@ -228,6 +229,7 @@ cmds testoptparser testrunner mkbenchmarkgenerator = map addGitAnnexCommonOption
        , Command.DiffDriver.cmd
        , Command.Smudge.cmd
        , Command.FilterProcess.cmd
+       , Command.Restage.cmd
        , Command.Undo.cmd
        , Command.Version.cmd
        , Command.RemoteDaemon.cmd
diff --git a/Command/Restage.hs b/Command/Restage.hs
new file mode 100644 (file)
index 0000000..2f7f5ce
--- /dev/null
@@ -0,0 +1,25 @@
+{- git-annex command
+ -
+ - Copyright 2022 Joey Hess <id@joeyh.name>
+ -
+ - Licensed under the GNU AGPL version 3 or higher.
+ -}
+
+module Command.Restage where
+
+import Command
+import qualified Annex
+import Annex.Link
+
+cmd :: Command
+cmd = command "restage" SectionPlumbing 
+       "estages unlocked files in the git index"
+       paramNothing (withParams seek)
+
+seek :: CmdParams -> CommandSeek
+seek = withNothing (commandAction start)
+
+start :: CommandStart
+start = starting "restage" (ActionItemOther Nothing) (SeekInput []) $ do
+       restagePointerFiles =<< Annex.gitRepo
+       next $ return True
index c7f89a85639a60bc362f011bca671c7e77cda947..5c8d84ba91cdec48534ba79ae13afc6feb42bae3 100644 (file)
@@ -26,7 +26,7 @@ start ::CommandStart
 start = go =<< currentView
   where
        go Nothing = giveup "Not in a view."
-       go (Just v) = starting "vcycle" (ActionItemOther Nothing) (SeekInput [])$ do
+       go (Just v) = starting "vcycle" (ActionItemOther Nothing) (SeekInput []) $ do
                let v' = v { viewComponents = vcycle [] (viewComponents v) }
                if v == v'
                        then do
index fc6f712b0d9561a9eaed13b4bf55d91be1961e74..8a3d2828481f36dd39d00953120b6e1a1da6c023 100644 (file)
@@ -91,4 +91,6 @@ I think I get it after I `annex move` and then `annex get` that file back. Just
 [[!meta author=yoh]]
 [[!tag projects/dandi]]
 
-> [[!meta title="annex.stalldetection prevents git-annex get from restaging unlocked files"]]
+[[!meta title="annex.stalldetection prevents git-annex get from restaging unlocked files"]]
+
+> [[fixed|done]] --[[Joey]]
diff --git a/doc/bugs/reports_file___34__modified__34___whenever_it_is_not/comment_16_4b8a360c38dfa4c8d22e3a96fbace0e5._comment b/doc/bugs/reports_file___34__modified__34___whenever_it_is_not/comment_16_4b8a360c38dfa4c8d22e3a96fbace0e5._comment
new file mode 100644 (file)
index 0000000..018139b
--- /dev/null
@@ -0,0 +1,33 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""status update"""
+ date="2022-09-23T19:57:38Z"
+ content="""
+I've implemented the log file. The stalled transferrer case is now handled.
+This bug is fixed.
+
+As to a few other cases I considered in comments upthread:
+
+When a get/drop was interrupted before it could restage, 
+the next get/drop will cause the necessary restaging for the 
+interrupted process to happen. However, this doesn't help if there's
+nothing left to get/drop. Should git-annex always run restagePointerFiles
+on shutdown? That would make any git-annex command handle the restaging.
+But it doesn't seem right for query commands to do potentially a lot of
+work to handle this case. Anyway, I don't think this needs to be dealt
+with in this bug report.
+
+When multiple processes try to restage at the same time, one will
+restage everything that all of them logged. The others will still display a
+warning to the user that they couldn't restage. It would be hard to avoid
+displaying that warning, since it does need to warn when it was
+unable to restage because git has the index locked at the time. Anyway,
+I think it's ok to display the message despite the files having been
+restaged, because it's the same as a later git-annex process handling the
+restaging. (It does seem like two transferrers belonging to the same parent
+could collide in this way, and one display the warning, which isn't great..)
+
+I also implemented a "git-annex restage" command that
+is an easier way to restage in the cases where git-annex is not able
+to do it itself.
+"""]]
diff --git a/doc/git-annex-restage.mdwn b/doc/git-annex-restage.mdwn
new file mode 100644 (file)
index 0000000..11d6914
--- /dev/null
@@ -0,0 +1,34 @@
+# NAME
+
+git-annex restage - restages unlocked files in the git index
+
+# SYNOPSIS
+
+git annex restage
+
+# DESCRIPTION
+
+Since getting or dropping an unlocked file modifies the file in the work
+tree, git needs to be told that the modification does not change the
+content that it has recorded (the annex pointer). Restaging the file
+accomplishes that.
+
+You do not normally need to run this command, because usually git-annex
+is able to restage unlocked files itself. There are some situations
+where git-annex needs to restage a file, but the git index is locked,
+and so it cannot. It will then display a warning suggesting you run this
+command.
+
+It's safe to run this command even after you have made a modification to an
+unlocked file.
+
+# SEE ALSO
+
+[[git-annex]](1)
+[[git-annex-smudge]](1)
+
+# AUTHOR
+
+Joey Hess <id@joeyh.name>
+
+Warning: Automatically converted into a man page by mdwn2man. Edit with care.
index d95ec25f6bffcaf56b7ee2ce49b81d7b49ac2f65..7b4d3f39825f74662b35b0fbac403748aa7a3e3e 100644 (file)
@@ -708,8 +708,8 @@ content from the key-value store.
 * `smudge`
 
   This command lets git-annex be used as a git filter driver, allowing
-  annexed files in the git repository to be unlocked at all times, instead
-  of being symlinks.
+  annexed files in the git repository to be unlocked regular files instead
+  of symlinks.
 
   See [[git-annex-smudge]](1) for details.
 
@@ -720,6 +720,12 @@ content from the key-value store.
 
   See [[git-annex-filter-process]](1) for details.
 
+* `restage`
+  
+  Restages unlocked files in the git index.
+
+  See [[git-annex-restage]](1) for details.
+
 * `findref [ref]`
 
   Lists files in a git ref. (deprecated)
index 052db279dbd6427c759d2350ca13dd8c486a6cf0..e3234ec4d73fa8a5e13b3bbac15378b311bdfe80 100644 (file)
@@ -775,6 +775,7 @@ Executable git-annex
     Command.Repair
     Command.Required
     Command.ResolveMerge
+    Command.Restage
     Command.RmUrl
     Command.Schedule
     Command.Semitrust